﻿using System;

namespace ProblemsSet
{
    public class Problem_52 : BaseProblem
    {
        public override object GetResult()
        {
            var cur = 0;
            while (true)
            {
                cur++;
                long res = (int) Math.Pow(10, (int) Math.Log10(cur) + 1) + cur;
                if (!MathLogic.GetDigitSet(res).IsSubsetOf(MathLogic.GetDigitSet(2*res)) || !MathLogic.GetDigitSet(2*res).IsSubsetOf(MathLogic.GetDigitSet(res)))
                    continue;
                if (!MathLogic.GetDigitSet(res).IsSubsetOf(MathLogic.GetDigitSet(3 * res)) || !MathLogic.GetDigitSet(3 * res).IsSubsetOf(MathLogic.GetDigitSet(res)))
                    continue;
                if (!MathLogic.GetDigitSet(res).IsSubsetOf(MathLogic.GetDigitSet(4 * res)) || !MathLogic.GetDigitSet(4 * res).IsSubsetOf(MathLogic.GetDigitSet(res)))
                    continue;
                if (!MathLogic.GetDigitSet(res).IsSubsetOf(MathLogic.GetDigitSet(5 * res)) || !MathLogic.GetDigitSet(5 * res).IsSubsetOf(MathLogic.GetDigitSet(res)))
                    continue;
                if (!MathLogic.GetDigitSet(res).IsSubsetOf(MathLogic.GetDigitSet(6 * res)) || !MathLogic.GetDigitSet(6 * res).IsSubsetOf(MathLogic.GetDigitSet(res)))
                    continue;
                return res;
            }
        }

        public override string Problem
        {
            get
            {
                return @"It can be seen that the number, 125874, and its double, 251748, contain exactly the same digits, but in a different order.

Find the smallest positive integer, x, such that 2x, 3x, 4x, 5x, and 6x, contain the same digits.";
            }
        }

        public override bool IsSolved
        {
            get
            {
                return true;
            }
        }

        public override object Answer
        {
            get
            {
                return 142857;
            }
        }

    }
}
